﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;
using System.Collections.Generic;//请先添加引用


namespace TierApplication
{
    /// <summary>
    /// 类T_Patient。
    /// </summary>
    public class T_Patient
    {
        public T_Patient()
        { }
        #region Model
        private decimal _patientid;
        private string _name;
        private string _sex;
        private string _idcard;
        private string _address;
        private string _birthday;
        private string _doctor;
        private decimal _height;
        private decimal _weight;
        private decimal _area;
        private string _FollowUpStatus;
        private string _correspondaddress;
        private string _postcode;
        private string _linkman1;
        private string _relation1;
        private string _phone1;
        private string _linkman2;
        private string _relation2;
        private string _phone2;
        private string _diagnosis0;
        private string _diagnosis1;
        private string _diagnosis2;
        private string _diagnosis3;
        private string _diagnosis4;
        private string _diagnosisicd;
        private string _pathologydiagnosis;
        private string _celltype;
        private string _tnmstage;
        private string _tumourstage;
        private string _opsdate;
        private string _ops;
        private string _remark;
        private string _survivalstatus;
        private string _deathdate;
        private string _deathcause;
        private string _createperson;
        private string _createdate;
        private string _researchsubject;
        private string _IDCardType;
        private string _DiseaseID;
        private string _ResearchSubjectStatus;
        private string _hspdatein;
        private string _hspdateout;
        private string _hsplapseto;
        private string _hspdeptidout;
        private string _hspsectionidout;

        public string ResearchSubjectStatus
        {
            get { return _ResearchSubjectStatus; }
            set { _ResearchSubjectStatus = value; }
        }
        private string _GroupDate;

        public string GroupDate
        {
            get { return _GroupDate; }
            set { _GroupDate = value; }
        }

        public string DiseaseID
        {
            get { return _DiseaseID; }
            set { _DiseaseID = value; }
        }

        public string IDCardType
        {
            get { return _IDCardType; }
            set { _IDCardType = value; }
        }

        public string ResearchSubject
        {
            get { return _researchsubject; }
            set { _researchsubject = value; }
        }
        private string _phone11;

        public string Phone11
        {
            get { return _phone11; }
            set { _phone11 = value; }
        }
        private string _phone21;

        public string Phone21
        {
            get { return _phone21; }
            set { _phone21 = value; }
        }

        private string _remark1;

        public string Remark1
        {
            get { return _remark1; }
            set { _remark1 = value; }
        }
        private string _DiagnosisDate;

        public string DiagnosisDate
        {
            get { return _DiagnosisDate; }
            set { _DiagnosisDate = value; }
        }


        /// <summary>
        /// 
        /// </summary>
        public decimal PatientID
        {
            set { _patientid = value; }
            get { return _patientid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Name
        {
            set { _name = value; }
            get { return _name; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Sex
        {
            set { _sex = value; }
            get { return _sex; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string IDCard
        {
            set { _idcard = value; }
            get { return _idcard; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Address
        {
            set { _address = value; }
            get { return _address; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Birthday
        {
            set { _birthday = value; }
            get { return _birthday; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Doctor
        {
            set { _doctor = value; }
            get { return _doctor; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal Height
        {
            set { _height = value; }
            get { return _height; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal Weight
        {
            set { _weight = value; }
            get { return _weight; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal Area
        {
            set { _area = value; }
            get { return _area; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string FollowUpStatus
        {
            set { _FollowUpStatus = value; }
            get { return _FollowUpStatus; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string CorrespondAddress
        {
            set { _correspondaddress = value; }
            get { return _correspondaddress; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string PostCode
        {
            set { _postcode = value; }
            get { return _postcode; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Linkman1
        {
            set { _linkman1 = value; }
            get { return _linkman1; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Relation1
        {
            set { _relation1 = value; }
            get { return _relation1; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Phone1
        {
            set { _phone1 = value; }
            get { return _phone1; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Linkman2
        {
            set { _linkman2 = value; }
            get { return _linkman2; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Relation2
        {
            set { _relation2 = value; }
            get { return _relation2; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Phone2
        {
            set { _phone2 = value; }
            get { return _phone2; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Diagnosis0
        {
            set { _diagnosis0 = value; }
            get { return _diagnosis0; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Diagnosis1
        {
            set { _diagnosis1 = value; }
            get { return _diagnosis1; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Diagnosis2
        {
            set { _diagnosis2 = value; }
            get { return _diagnosis2; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Diagnosis3
        {
            set { _diagnosis3 = value; }
            get { return _diagnosis3; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Diagnosis4
        {
            set { _diagnosis4 = value; }
            get { return _diagnosis4; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string DiagnosisICD
        {
            set { _diagnosisicd = value; }
            get { return _diagnosisicd; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string PathologyDiagnosis
        {
            set { _pathologydiagnosis = value; }
            get { return _pathologydiagnosis; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string CellType
        {
            set { _celltype = value; }
            get { return _celltype; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string TNMStage
        {
            set { _tnmstage = value; }
            get { return _tnmstage; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string TumourStage
        {
            set { _tumourstage = value; }
            get { return _tumourstage; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string OPSDate
        {
            set { _opsdate = value; }
            get { return _opsdate; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string OPS
        {
            set { _ops = value; }
            get { return _ops; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Remark
        {
            set { _remark = value; }
            get { return _remark; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string SurvivalStatus
        {
            set { _survivalstatus = value; }
            get { return _survivalstatus; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string DeathDate
        {
            set { _deathdate = value; }
            get { return _deathdate; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string DeathCause
        {
            set { _deathcause = value; }
            get { return _deathcause; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string CreatePerson
        {
            set { _createperson = value; }
            get { return _createperson; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string CreateDate
        {
            set { _createdate = value; }
            get { return _createdate; }
        }
        		/// <summary>
		/// 入院日期
		/// </summary>
		public string HspDateIn
		{
			set{ _hspdatein=value;}
			get{return _hspdatein;}
		}
		/// <summary>
		/// 出院日期
		/// </summary>
		public string HspDateOut
		{
			set{ _hspdateout=value;}
			get{return _hspdateout;}
		}
		/// <summary>
		/// 转归
		/// </summary>
		public string HspLapseTo
		{
			set{ _hsplapseto=value;}
			get{return _hsplapseto;}
		}
		/// <summary>
		/// 出院科室
		/// </summary>
		public string HspDeptIDOut
		{
			set{ _hspdeptidout=value;}
			get{return _hspdeptidout;}
		}
		/// <summary>
		/// 
		/// </summary>
        public string HspSectionIDOut
        {
            set { _hspsectionidout = value; }
            get { return _hspsectionidout; }
        }


        private string _DeptName;

        public string DeptName
        {
            get { return _DeptName; }
            set { _DeptName = value; }
        }
        private string _SectionName;

        public string SectionName
        {
            get { return _SectionName; }
            set { _SectionName = value; }
        }
        private string _DoctorName;

        public string DoctorName
        {
            get { return _DoctorName; }
            set { _DoctorName = value; }
        }

        private string _HspInNo;

        public string HspInNo
        {
            get { return _HspInNo; }
            set { _HspInNo = value; }
        }
        #endregion Model


        #region  成员方法


        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(decimal PatientID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Patient where PatientID=" + PatientID + "");
            return DbHelperSQL.Exists(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [T_Patient](");
            strSql.Append("PatientID,Name,Sex,DiseaseID,IDCardType,IDCard,Address,Birthday,Doctor,Height,Weight,Area,FollowUpStatus,CorrespondAddress,PostCode,Linkman1,Relation1,Phone1,Linkman2,Relation2,Phone2,Diagnosis0,Diagnosis1,Diagnosis2,Diagnosis3,Diagnosis4,DiagnosisICD,PathologyDiagnosis,DiagnosisDate,CellType,TNMStage,TumourStage,OPSDate,OPS,Remark,SurvivalStatus,DeathDate,DeathCause,CreatePerson,ResearchSubject,Phone11,Phone21,Remark1,GroupDate,ResearchSubjectStatus,CreateDate,HspDateIn,HspDateOut,HspLapseTo,HspDeptIDOut,HspInNo,HspSectionIDOut");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("" + PatientID + ",");
            strSql.Append("'" + Name + "',");
            strSql.Append("'" + Sex + "',");
            strSql.Append("'" + DiseaseID + "',");
            strSql.Append("'" + IDCardType + "',");
            strSql.Append("'" + IDCard + "',");
            strSql.Append("'" + Address + "',");
            if (Birthday != "")
            {
                strSql.Append("'" + Birthday + "',");
            }
            else
            {
                strSql.Append("null,");
            }
            strSql.Append("'" + Doctor + "',");
            strSql.Append("" + Height + ",");
            strSql.Append("" + Weight + ",");
            strSql.Append("" + Area + ",");
            strSql.Append("'" + FollowUpStatus + "',");
            strSql.Append("'" + CorrespondAddress + "',");
            strSql.Append("'" + PostCode + "',");
            strSql.Append("'" + Linkman1 + "',");
            strSql.Append("'" + Relation1 + "',");
            strSql.Append("'" + Phone1 + "',");
            strSql.Append("'" + Linkman2 + "',");
            strSql.Append("'" + Relation2 + "',");
            strSql.Append("'" + Phone2 + "',");
            strSql.Append("'" + Diagnosis0 + "',");
            strSql.Append("'" + Diagnosis1 + "',");
            strSql.Append("'" + Diagnosis2 + "',");
            strSql.Append("'" + Diagnosis3 + "',");
            strSql.Append("'" + Diagnosis4 + "',");
            strSql.Append("'" + DiagnosisICD + "',");
            strSql.Append("'" + PathologyDiagnosis + "',");
            if (DiagnosisDate != "")
            {
                strSql.Append("'" + DiagnosisDate + "',");
            }
            else
            {
                strSql.Append("null,");
            }
            strSql.Append("'" + CellType + "',");
            strSql.Append("'" + TNMStage + "',");
            strSql.Append("'" + TumourStage + "',");
            if (OPSDate != "")
            {
                strSql.Append("'" + OPSDate + "',");
            }
            else
            {
                strSql.Append("null,");
            }
            strSql.Append("'" + OPS + "',");
            strSql.Append("'" + Remark + "',");
            strSql.Append("'" + SurvivalStatus + "',");
            if (DeathDate != "")
            {
                strSql.Append("'" + DeathDate + "',");
            }
            else
            {
                strSql.Append("null,");
            }
            strSql.Append("'" + DeathCause + "',");
            strSql.Append("'" + CreatePerson + "',");
            strSql.Append("'" + ResearchSubject + "',");
            strSql.Append("'" + Phone11 + "',");
            strSql.Append("'" + Phone21 + "',");
            strSql.Append("'" + Remark1 + "',");
            if (GroupDate != "")
            {
                strSql.Append("'" + GroupDate + "',");
            }
            else
            {
                strSql.Append("null,");
            }
            strSql.Append("'" + ResearchSubjectStatus + "',");
            strSql.Append("getdate(),");
            if (HspDateIn != "")
            {
                strSql.Append("'" + HspDateIn + "',");
            }
            else
            {
                strSql.Append("null,");
            }
            if (HspDateOut != "")
            {
                strSql.Append("'" + HspDateOut + "',");
            }
            else
            {
                strSql.Append("null,");
            }
            strSql.Append("'" + HspLapseTo + "',");
            strSql.Append("'" + HspDeptIDOut + "',");
            strSql.Append("'" + HspInNo + "',");
            strSql.Append("'" + HspSectionIDOut + "'");
            strSql.Append(")");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Patient set ");
            strSql.Append("Name='" + Name + "',");
            strSql.Append("DiseaseID='" + DiseaseID + "',");
            strSql.Append("Sex='" + Sex + "',");
            strSql.Append("IDCard='" + IDCard + "',");
            strSql.Append("Address='" + Address + "',");
            if (Birthday != "")
            {
                strSql.Append("Birthday='" + Birthday + "',");
            }
            else
            {
                strSql.Append("Birthday=null,");
            }

            strSql.Append("IDCardType='" + IDCardType + "',");
            strSql.Append("Doctor='" + Doctor + "',");
            strSql.Append("Height=" + Height + ",");
            strSql.Append("Weight=" + Weight + ",");
            strSql.Append("Area=" + Area + ",");
            strSql.Append("FollowUpStatus='" + FollowUpStatus + "',");
            strSql.Append("CorrespondAddress='" + CorrespondAddress + "',");
            strSql.Append("PostCode='" + PostCode + "',");
            strSql.Append("Linkman1='" + Linkman1 + "',");
            strSql.Append("Relation1='" + Relation1 + "',");
            strSql.Append("Phone1='" + Phone1 + "',");
            strSql.Append("Linkman2='" + Linkman2 + "',");
            strSql.Append("Relation2='" + Relation2 + "',");
            strSql.Append("Phone2='" + Phone2 + "',");
            strSql.Append("Diagnosis0='" + Diagnosis0 + "',");
            strSql.Append("Diagnosis1='" + Diagnosis1 + "',");
            strSql.Append("Diagnosis2='" + Diagnosis2 + "',");
            strSql.Append("Diagnosis3='" + Diagnosis3 + "',");
            strSql.Append("Diagnosis4='" + Diagnosis4 + "',");
            strSql.Append("DiagnosisICD='" + DiagnosisICD + "',");
            strSql.Append("PathologyDiagnosis='" + PathologyDiagnosis + "',");
            if (DiagnosisDate != "")
            {
                strSql.Append("DiagnosisDate='" + DiagnosisDate + "',");
            }
            else
            {
                strSql.Append("DiagnosisDate=null,");
            }
            strSql.Append("CellType='" + CellType + "',");
            strSql.Append("TNMStage='" + TNMStage + "',");
            strSql.Append("TumourStage='" + TumourStage + "',");
            if (OPSDate != "")
            {
                strSql.Append("OPSDate='" + OPSDate + "',");
            }
            else
            {
                strSql.Append("OPSDate=null,");
            }
            strSql.Append("OPS='" + OPS + "',");
            strSql.Append("Remark='" + Remark + "',");
            strSql.Append("SurvivalStatus='" + SurvivalStatus + "',");
            if (DeathDate != "")
            {
                strSql.Append("DeathDate='" + DeathDate + "',");
            }
            else
            {
                strSql.Append("DeathDate=null,");
            }
            if (GroupDate != "")
            {
                strSql.Append("GroupDate='" + GroupDate + "',");
            }
            else
            {
                strSql.Append("GroupDate=null,");
            }
            strSql.Append("ResearchSubjectStatus='" + ResearchSubjectStatus + "',");
            strSql.Append("DeathCause='" + DeathCause + "',");
            strSql.Append("CreatePerson='" + CreatePerson + "',");
            strSql.Append("ResearchSubject='" + ResearchSubject + "',");
            strSql.Append("Phone11='" + Phone11 + "',");
            strSql.Append("Phone21='" + Phone21 + "',");
            strSql.Append("Remark1='" + Remark1 + "',");
            if (HspDateIn != "")
            {
                strSql.Append("HspDateIn='" + HspDateIn + "',");
            }
            else
            {
                strSql.Append("HspDateIn=null,");
            }
            if (HspDateOut != "")
            {
                strSql.Append("HspDateOut='" + HspDateOut + "',");
            }
            else
            {
                strSql.Append("HspDateOut=null,");
            }
            strSql.Append("HspLapseTo='" + HspLapseTo + "',");
            strSql.Append("HspDeptIDOut='" + HspDeptIDOut + "',");
            strSql.Append("HspInNo='" + HspInNo + "',");
            strSql.Append("HspSectionIDOut='" + HspSectionIDOut + "'");
            //strSql.Append("CreateDate='"+CreateDate+"'");
            strSql.Append(" where PatientID=" + PatientID + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string PatientID)
        {           
            List<String> SqlStringList = new List<string>();
            SqlStringList.Add("delete T_Patient where PatientID=" + PatientID + "");
            //SqlStringList.Add("delete T_ChemCureCtc where ChemCureID in (Select ID from T_ChemCure where PatientID = " + PatientID + ")");
            //SqlStringList.Add("delete T_ChemCure where PatientID =" + PatientID + "");
            DbHelperSQL.ExecuteSqlTran(SqlStringList);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(int iPatientID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append("PatientID,Name,Sex,DiseaseID,IDCardType,IDCard,Address,Birthday,Doctor,Height,Weight,Area,FollowUpStatus,CorrespondAddress,PostCode,Linkman1,Relation1,Phone1,Linkman2,Relation2,Phone2,Diagnosis0,Diagnosis1,Diagnosis2,Diagnosis3,Diagnosis4,DiagnosisICD,PathologyDiagnosis,DiagnosisDate,CellType,TNMStage,TumourStage,OPSDate,OPS,Remark,SurvivalStatus,DeathDate,DeathCause,CreatePerson,ResearchSubject,Phone11,Phone21,Remark1,GroupDate,ResearchSubjectStatus,CreateDate,HspDateIn,HspDateOut,HspLapseTo, ");
            strSql.Append(" HspDeptIDOut,(Select DeptName from P_Department where DeptID=a.HspDeptIDOut) DeptName, ");
            strSql.Append(" HspSectionIDOut,(Select SectionName from P_Section where SectionID=a.HspSectionIDOut) SectionName, ");
            strSql.Append(" (Select UserName from P_User where UserID=a.Doctor) DoctorName,HspInNo  ");
            strSql.Append(" from T_Patient a ");
            strSql.Append(" where PatientID=" + iPatientID + "");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["PatientID"].ToString() != "")
                {
                    PatientID = decimal.Parse(ds.Tables[0].Rows[0]["PatientID"].ToString());
                }
                Name = ds.Tables[0].Rows[0]["Name"].ToString();
                Sex = ds.Tables[0].Rows[0]["Sex"].ToString();
                DiseaseID = ds.Tables[0].Rows[0]["DiseaseID"].ToString();
                IDCardType = ds.Tables[0].Rows[0]["IDCardType"].ToString();
                IDCard = ds.Tables[0].Rows[0]["IDCard"].ToString();
                Address = ds.Tables[0].Rows[0]["Address"].ToString();
                Birthday = ds.Tables[0].Rows[0]["Birthday"].ToString();
                Doctor = ds.Tables[0].Rows[0]["Doctor"].ToString();
                if (ds.Tables[0].Rows[0]["Height"].ToString() != "")
                {
                    Height = decimal.Parse(ds.Tables[0].Rows[0]["Height"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Weight"].ToString() != "")
                {
                    Weight = decimal.Parse(ds.Tables[0].Rows[0]["Weight"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Area"].ToString() != "")
                {
                    Area = decimal.Parse(ds.Tables[0].Rows[0]["Area"].ToString());
                }
                FollowUpStatus = ds.Tables[0].Rows[0]["FollowUpStatus"].ToString();
                CorrespondAddress = ds.Tables[0].Rows[0]["CorrespondAddress"].ToString();
                PostCode = ds.Tables[0].Rows[0]["PostCode"].ToString();
                Linkman1 = ds.Tables[0].Rows[0]["Linkman1"].ToString();
                Relation1 = ds.Tables[0].Rows[0]["Relation1"].ToString();
                Phone1 = ds.Tables[0].Rows[0]["Phone1"].ToString();
                Linkman2 = ds.Tables[0].Rows[0]["Linkman2"].ToString();
                Relation2 = ds.Tables[0].Rows[0]["Relation2"].ToString();
                Phone2 = ds.Tables[0].Rows[0]["Phone2"].ToString();
                Diagnosis0 = ds.Tables[0].Rows[0]["Diagnosis0"].ToString();
                Diagnosis1 = ds.Tables[0].Rows[0]["Diagnosis1"].ToString();
                Diagnosis2 = ds.Tables[0].Rows[0]["Diagnosis2"].ToString();
                Diagnosis3 = ds.Tables[0].Rows[0]["Diagnosis3"].ToString();
                Diagnosis4 = ds.Tables[0].Rows[0]["Diagnosis4"].ToString();
                DiagnosisICD = ds.Tables[0].Rows[0]["DiagnosisICD"].ToString();
                PathologyDiagnosis = ds.Tables[0].Rows[0]["PathologyDiagnosis"].ToString();
                DiagnosisDate = ds.Tables[0].Rows[0]["DiagnosisDate"].ToString();
                CellType = ds.Tables[0].Rows[0]["CellType"].ToString();
                TNMStage = ds.Tables[0].Rows[0]["TNMStage"].ToString();
                TumourStage = ds.Tables[0].Rows[0]["TumourStage"].ToString();
                OPSDate = ds.Tables[0].Rows[0]["OPSDate"].ToString();
                OPS = ds.Tables[0].Rows[0]["OPS"].ToString();
                Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                SurvivalStatus = ds.Tables[0].Rows[0]["SurvivalStatus"].ToString();
                DeathDate = ds.Tables[0].Rows[0]["DeathDate"].ToString();
                DeathCause = ds.Tables[0].Rows[0]["DeathCause"].ToString();
                CreatePerson = ds.Tables[0].Rows[0]["CreatePerson"].ToString();
                ResearchSubject = ds.Tables[0].Rows[0]["ResearchSubject"].ToString();
                Phone11 = ds.Tables[0].Rows[0]["Phone11"].ToString();
                Phone21 = ds.Tables[0].Rows[0]["Phone21"].ToString();
                Remark1 = ds.Tables[0].Rows[0]["Remark1"].ToString();
                GroupDate = ds.Tables[0].Rows[0]["GroupDate"].ToString();
                ResearchSubjectStatus = ds.Tables[0].Rows[0]["ResearchSubjectStatus"].ToString();
                CreateDate = ds.Tables[0].Rows[0]["CreateDate"].ToString();
                HspDateIn = ds.Tables[0].Rows[0]["HspDateIn"].ToString();
                HspDateOut = ds.Tables[0].Rows[0]["HspDateOut"].ToString();
                HspLapseTo = ds.Tables[0].Rows[0]["HspLapseTo"].ToString();
                HspDeptIDOut = ds.Tables[0].Rows[0]["HspDeptIDOut"].ToString();
                HspSectionIDOut = ds.Tables[0].Rows[0]["HspSectionIDOut"].ToString();
                DeptName = ds.Tables[0].Rows[0]["DeptName"].ToString();
                SectionName = ds.Tables[0].Rows[0]["SectionName"].ToString();
                DoctorName = ds.Tables[0].Rows[0]["DoctorName"].ToString();
                HspInNo = ds.Tables[0].Rows[0]["HspInNo"].ToString();
            }
        }

        #endregion  成员方法


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select '0' IsChecked,[PatientID],[Name],[Sex],[IDCardType],[IDCard],[Address],Convert(varchar(10),Birthday,21) Birthday,[Doctor], DiseaseID,");
            strSql.Append("[Height],[Weight],[Area],[FollowUpStatus],[CorrespondAddress],[PostCode],[Linkman1],");
            strSql.Append("[Relation1],[Phone1],[Linkman2],[Relation2],[Phone2],[Diagnosis0],[Diagnosis1],[Diagnosis2],");
            strSql.Append("[Diagnosis3],[Diagnosis4],[DiagnosisICD],[PathologyDiagnosis],Convert(varchar(10),DiagnosisDate,21) DiagnosisDate,[CellType],Case TNMStage when 'TNM' then '' else TNMStage end TNMStage,[TumourStage],");
            strSql.Append("Convert(varchar(10),OPSDate,21) OPSDate,[OPS],[Remark],[SurvivalStatus],[DeathDate],[DeathCause],[CreatePerson],ResearchSubject,Phone11,Phone21,Remark1,[CreateDate],");
            strSql.Append("(Select DiseaseName from T_Disease where DiseaseID=a.DiseaseID) DiseaseName,");
            strSql.Append("(Select CodeName from c_sex where CodeID=a.sex) SexName,");
            strSql.Append("(Select UserName from P_user where UserID=a.Doctor) DoctorName,");
            strSql.Append("(Select CodeName from C_Dmb where DDType='TumourStage' and CodeID=a.TumourStage) TumourStageName,");
            strSql.Append("(Select CodeName from C_Dmb where DDType='SurvivalStatus' and CodeID=a.SurvivalStatus) SurvivalStatusName,");
            strSql.Append("(Select CodeName from C_Dmb where DDType='DeathCause' and CodeID=a.DeathCause) DeathCauseName,");
            strSql.Append("PathologyDiagnosis PathologyDiagnosisName,");
            strSql.Append("Convert(varchar(10),GroupDate,21) GroupDate, ");
            strSql.Append("(Select CodeName from C_Dmb where DDType='ResearchSubjectStatus' and CodeID=a.ResearchSubjectStatus) ResearchSubjectStatusName,");
            strSql.Append("(Select CodeName from C_Dmb where DDType='FollowUpStatus' and CodeID=a.DeathCause) FollowUpStatusName,");
            strSql.Append("(Select CodeName from C_Dmb where DDType='ResearchSubject' and CodeID=a.ResearchSubject) ResearchSubjectName,");
            strSql.Append("Convert(varchar(10),HspDateIn,21) HspDateIn,");
            strSql.Append("Convert(varchar(10),HspDateOut,21) HspDateOut,");
            strSql.Append("HspLapseTo,HspInNo,");
            strSql.Append("HspDeptIDOut,(Select DeptName from p_department where DeptID=a.HspDeptIDOut) HspDeptIDOutName");
            strSql.Append("HspSectionIDOut,(Select DeptName from p_department where DeptID=a.HspSectionIDOut) HspSectionIDOutName");
            strSql.Append(" FROM T_Patient a ");
            if (strWhere.Trim() != "")
            {

                strSql.Append(" where 1=1 " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        //public static DataSet GetPatinetChart(int PatientID)
        //{

        //    SqlParameter[] parameters ={
        //            new SqlParameter("@ai_PatientID", SqlDbType.Int, 4)
        //    };
        //    parameters[0].Value = PatientID;
        //    return DbHelperSQL.RunProcedure("dbo.GetPatientChart", parameters, "PatinetChart");
        //}

        public static DataSet GetPatientChart(int PatientID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select (convert(char(10), HspDateIn,21)) ChartDateTime,0 ChartValue,'入院' ChartTextAna,PatientID ID,'RY' EventType");
            strSql.Append(" FROM T_Patient");
            strSql.Append(" where PatientID=" + PatientID + " and HspDateIn is not null  ");
            strSql.Append(" union");
            strSql.Append(" select (convert(char(10), HspDateOut,21)) ChartDateTime,0 ChartValue,'出院' ChartTextAna,PatientID ID,'CY' EventType");
            strSql.Append(" FROM T_Patient");
            strSql.Append(" where PatientID=" + PatientID + " and HspDateOut is not null  ");
            strSql.Append(" union");
            strSql.Append(" select (convert(char(10), DeathDate,21)) ChartDateTime,0 ChartValue,'身故' ChartTextAna,PatientID ID,'DD' EventType");
            strSql.Append(" FROM T_Patient");
            strSql.Append(" where PatientID=" + PatientID + " and DeathDate is not null  ");
            strSql.Append(" union");
            strSql.Append(" select (convert(char(10), FollowUpDate,21)) ChartDateTime,0 ChartValue,'电话随访' ChartTextAna,FollowUpID ID,'DHSF' EventType");
            strSql.Append(" FROM T_FollowUp");
            strSql.Append(" where PatientID=" + PatientID + " and FollowUpDate is not null and DialResult='1' and FollowUpMode='1' ");
            strSql.Append(" union");
            strSql.Append(" select (convert(char(10), FollowUpDate,21)) ChartDateTime,0 ChartValue,'信函随访' ChartTextAna,FollowUpID ID,'XHSF' EventType");
            strSql.Append(" FROM T_FollowUp");
            strSql.Append(" where PatientID=" + PatientID + " and FollowUpDate is not null and FollowUpMode='2' ");
            strSql.Append(" union");
            strSql.Append(" select (convert(char(10), FollowUpDate,21)) ChartDateTime,0 ChartValue,'短信随访' ChartTextAna,FollowUpID ID,'DXSF' EventType");
            strSql.Append(" FROM T_FollowUp");
            strSql.Append(" where PatientID=" + PatientID + " and FollowUpDate is not null and FollowUpMode='4' ");
            return DbHelperSQL.Query(strSql.ToString());     
        }

        #region 统计
        public static DataSet GetReportDiseaseByMonth(string sYear)
        {

            SqlParameter[] parameters ={
                    new SqlParameter("@ac_year", SqlDbType.VarChar, 4)
            };
            parameters[0].Value = sYear;
            return DbHelperSQL.RunProcedure("dbo.ReportDiseaseByMonth", parameters, "ReportDiseaseByMonth");
        }

        public static DataSet GetReportDiseaseByMonthEndDate(string sYear)
        {

            SqlParameter[] parameters ={
                    new SqlParameter("@ac_year", SqlDbType.VarChar, 4)
            };
            parameters[0].Value = sYear;
            return DbHelperSQL.RunProcedure("dbo.ReportDiseaseByMonthEndDate", parameters, "ReportDiseaseByMonthEndDate");
        }

        public static DataSet GetReportPatientInput(string sYear)
        {

            SqlParameter[] parameters ={
                    new SqlParameter("@ac_year", SqlDbType.VarChar, 4)
            };
            parameters[0].Value = sYear;
            return DbHelperSQL.RunProcedure("dbo.ReportPatientInput", parameters, "ReportPatientInput");
        }
        #endregion
    }
}

